package sfsu.memopad;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {
	Context mContext;
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();


	/*public HelloItemizedOverlay(Drawable defaultMarker) {
		super(defaultMarker);
		// TODO Auto-generated constructor stub
	}*/
	
	public HelloItemizedOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
		}
	
	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}

	@Override
	/*protected OverlayItem createItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}*/
	
	protected OverlayItem createItem(int i) {
		  return mOverlays.get(i);
		}

	@Override
	/*public int size() {
		// TODO Auto-generated method stub
		return 0;
	}*/
	
	public int size() {
		  return mOverlays.size();
		}
	
	protected boolean onTap(int index) {
		OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		
		dialog.setTitle(mOverlays.get(index).getTitle());
		dialog.setMessage(mOverlays.get(index).getSnippet());
		
		dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton){
				dialog.cancel();
				//callReturnToActivity();
			}
		});
		
		dialog.setNegativeButton("Cancel",	new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton){
				dialog.cancel();
			}
		});
		dialog.show();
		//return super.onTap(index);
		return true;
		}
	
		public void callReturnToActivity(){
			//Intent myIntent = new Intent(mContext, NoteEdit.class);
            //myIntent.putExtra( "lat", 5);
            //myIntent.putExtra( "long", 6);
            //mContext.startActivity(myIntent);
		}

}
